﻿using System.Configuration;

namespace ErrorDumper.Configuration {
    public class ErrorDumperSection : ConfigurationSection {
        public static readonly string SectionName = "errorDumper";

        public static ErrorDumperSection GetSection() {
            return ConfigurationManager.GetSection(SectionName) as ErrorDumperSection;
        }

        internal static ErrorDumperSection GetValidatedSection() {
            var section = GetSection();
            if (section == null)
                throw new ConfigurationErrorsException(string.Format("Section '{0}' must be configured", SectionName));
            return section;
        }

        public static void RefreshSection() {
            ConfigurationManager.RefreshSection(SectionName);
        }

        [ConfigurationProperty("dataSource")]
        public DataSourceElement DataSource {
            get { return (DataSourceElement)this["dataSource"]; }
        }

        [ConfigurationProperty("handler")]
        public HandlerElement Handler {
            get { return (HandlerElement)this["handler"]; }
        }

        [ConfigurationProperty("provider")]
        public ProviderElement Provider {
            get { return (ProviderElement)this["provider"]; }
        }

        [ConfigurationProperty("filters")]
        public FilterElementCollection Filters {
            get { return (FilterElementCollection)this["filters"]; }
        }
    }
}